$().ready( function() {
    
    jQuery.validator.addMethod("dateITA", function(value, element) {
        var check = false;
        var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
        if( re.test(value)){
            var adata = value.split('/');
            var gg = parseInt(adata[0],10);
            var mm = parseInt(adata[1],10);
            var aaaa = parseInt(adata[2],10);
            var xdata = new Date(aaaa,mm-1,gg);
            if ( ( xdata.getFullYear() == aaaa ) 
                && ( xdata.getMonth () == mm - 1 ) 
                && ( xdata.getDate() == gg ) )
                check = true;
            else
                check = false;
        } else
            check = false;
        return this.optional(element) || check;
    }
    );

    $("#StatEmployeeForm").validate( {
        rules: {
            "data[Stat][date_from]": {
                required: true,
                dateITA: true
            },
            "data[Stat][date_to]": {
                required: true,
                dateITA: true
            }
        },
        messages: {
            "data[Stat][date_from]": {
                required: "<?php __('Ingrese una fecha') ?>",
                dateITA: "<?php __('Ingrese una fecha válida') ?>"
            },
            "data[Stat][date_to]": {
                required: "<?php __('Ingrese una fecha') ?>",
                dateITA: "<?php __('Ingrese una fecha válida') ?>"
            }
        }

    } );
} );